package com.cloud.environment;

import com.cloud.utils.ApplicationContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;

/**
 * 基于配置文件获取环境变量
 */
@Component
@Slf4j
public class ApplicationContextEnvironment implements ApplicationRunner {

    /**
     * java   -Dcom.mayikt=mayikt.com   -jar
     *
     * @param args
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        ConfigurableEnvironment environment = (ConfigurableEnvironment) ApplicationContextHolder.getApplicationContext().getEnvironment();
        String javaHome = environment.getProperty("java_home");
        String comMayikt = environment.getProperty("com.mayikt");
        log.info("环境变量：" + javaHome + "," + comMayikt);
    }
}

